const input = [
    {
        username: 'zhangsan',
        starCount: 10,
        content: '嘻嘻嘻',
    },
    {
        username: 'lisi',
        starCount: 122,
        content: '嘿嘿',
    },
    {
        username: 'lisi',
        starCount: 99,
        content: '呵呵',
    },
    {
        username: 'zhangsan',
        starCount: 12,
        content: '哈哈哈',
    },
    {
        username: 'wangwu',
        starCount: 6,
        content: '嗯嗯',
    },
];

const output = {
    starCount: {
        zhangsan: 22,
        lisi: 221,
        wangwu: 6,
    },
    commentCount: {
        zhangsan: 2,
        lisi: 2,
        wangwu: 1,
    },
};

function getTotal(input) {

    const starCount = {};
    const commentCount = {};
    for (const item of input) {
        const {
            username,
            starCount: s, // 对象解构赋值 重命名
        } = item;
        if (!commentCount[username]) {
            commentCount[username] = input.filter(cmt => cmt.username === username).length;
            starCount[username] = s;
        } else {
            starCount[username] += s;
        }
    }

    return {
        starCount,
        commentCount,
    };
}


console.log(getTotal(input));
